<template>
    <div  ref="chart" class="chart"></div>
</template>
<script>
import echarts from '@/lib/echarts'
import { getElementSize, getMax } from '@/lib/util'
export default {
    data(){
        return{
          chart: null, //echart图表对象
           dataArr :0,
           max:0,
            colorSet: {
                color: '#e18c29'
            }
        }
    },
      mounted() {
        const that = this
          that.dataArr=that.info
          that.max=that.all
          that.colorSet.color=that.bgColor
          that.init()
         
    },
    watch:{
        'info' (newVal,oldVal){
          this.dataArr=newVal
           this.init()
        },
        'all' (newVal,oldVal){
           this.max=newVal
           this.init()
        }
    },
    props:['info','all','bgColor'],
    methods:{
        init(){
            var that=this
              that.chart = echarts.init(that.$refs.chart,false)
           
          let  option = {
    tooltip: {
        formatter: "{a} <br/>{b} : {c}%"
    },

    series: [{   
            type: "gauge",
            // center: ['20%', '50%'],
            radius: '70%',
            splitNumber: 10,
            axisLine: {
                lineStyle: {
                    color: [
                        [that.dataArr / this.all, that.colorSet.color],
                        [1, "#2F8DF4"]
                    ],
                    width: 8
                }
            },
            axisLabel: {
                show: false,
            },
            axisTick: {
                show: false,

            },
            splitLine: {
                show: false,
            },
            itemStyle: {
                show: false,
            },
            detail: {
                formatter: function(value) { 
                        return value;
                },
                offsetCenter: [0, 82],
                textStyle: {
                    padding: [0, 0, 0, 0],
                    fontSize: 18,
                    fontWeight: '700',
                    color: that.colorSet.color
                }
            },
            title: { //标题
                show: false,
                offsetCenter: [0, 46], // x, y，单位px
                textStyle: {
                    color: "#fff",
                    fontSize: 12, //表盘上的标题文字大小
                    fontWeight: 400,
                    fontFamily: 'PingFangSC'
                }
            },
            data: [{
                value: that.dataArr / this.all*100,
                tooltip:{
                    show:false
                },
            }],
            pointer: {
                show: true,
                length: '75%',
                radius: '20%',
                width: 5, //指针粗细
            },
           animationDelay:2000,
           animationDuration:6000,
        },
        {
            name: '外部刻度',
            type: 'gauge',
            //  center: ['20%', '50%'],
            radius: '100%',
            min: 0, //最小刻度
            max: that.max, //最大刻度
            splitNumber: 7, //刻度数量
            startAngle: 225,
            endAngle: -45,
            axisLine: {
                show:true,
                lineStyle: {
                    width: 1,
                    color: [
                        [1, 'rgba(0,0,0,0)']
                    ]
                }
            }, //仪表盘轴线
            axisLabel: {
                show: false,
                color: that.colorSet.color,
                distance: 10,
                formatter: function(v) {
                    switch (v + '') {
                        case '0':
                            return '0';
                        case '1000':
                            return '1000';           
                    }
                }
            }, //刻度标签。
            axisTick: {
                show: false,
                splitNumber:3,
                lineStyle: {
                    color: "#1d51d2", //用颜色渐变函数不起作用
                    width: 1,
                },
                length: -3
            }, //刻度样式
            splitLine: {
                show: false,
                length: -5,
                lineStyle: {
                    color: "#1d51d2", //用颜色渐变函数不起作用
                }
            }, //分隔线样式
            detail: {
                show: false
            },
            pointer: {
                show: false
            }
        },
    ]
};
 that.chart.setOption(option)

},
    },
    
}
</script>
<style scoped>
.chart{
    width:100%!important;
    height:100%!important;
}
</style>